package utils
{
	import app.mvc.controller.editor.EditorBaseCommand;
	
	import org.puremvc.as3.patterns.observer.Notification;

	public class UtilsEditorCommand
	{
		/**
		 * 历史可撤销命令集合
		 * @default 
		 */
		public static var historyCommands:Vector.<EditorBaseCommand> = new Vector.<EditorBaseCommand>();
		
		/**
		 * 最近被撤销的命令集合
		 * @default 
		 */
		public static var editorRedoCommands:Vector.<EditorBaseCommand> = new Vector.<EditorBaseCommand>();
		
		/**
		 * 加入历史记录
		 * @param command
		 */
		public static function addToHistory(command:EditorBaseCommand):void
		{
			historyCommands.push(command);
		}
		
		/**
		 * 恢复最近撤销的动作,一旦有新命令，最近撤销队列清空
		 */
		public static function redoCommand():void
		{
			var command:EditorBaseCommand = editorRedoCommands.pop();
			if(!command)
				return;
			command.redo();
			historyCommands.push(command);		//恢复的动作，同时也能再被撤销
		}
		
		/**
		 * 撤销当前操作
		 */
		public static function undoCommand():void
		{
			var command:EditorBaseCommand = historyCommands.pop();
			if(!command)
				return;
			command.undo();
			editorRedoCommands.push(command);
		}
		
		/**
		 * 清空可撤销命令集合
		 */
		public static function clearUndoCommands():void
		{
			historyCommands = new Vector.<EditorBaseCommand>(); 
		}
		
		/**
		 * 清空可恢复命令集合
		 */
		public static function clearRedoCommands():void
		{
			editorRedoCommands = new Vector.<EditorBaseCommand>(); 
		}
		
		/**
		 * 创建一个命令
		 * @param classString
		 * @param $body
		 * @param $type
		 * @return 
		 */
		public static function createCommand(classString:Class,$body:Object,$type:String=null):EditorBaseCommand
		{
			var command:EditorBaseCommand = new classString();
			command.notification = new Notification("",$body,$type);
			return command;
		}
	}
}